<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置我的资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/adminstatic/base/base.css"/>
    <script src="/adminstatic/base/baseCss.js"></script>
    <style type="text/css">
        .layui-form-label {
            width: 120px;
        }

        .img-tag {
            width: 100%;
            line-height: 25px;
            background-color: rgba(0, 0, 0, 0.3);
            font-size: 14px;
            color: white;
            text-align: center;
            position: absolute;
            bottom: 0;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form" lay-filter="">
                        <input type="hidden" name="id" value="<%=id%>"/>
                        <input type="hidden" name="url" value="<%=avatar%>"/>
                        <div class="layui-form-item">
                            <label class="layui-form-label">我的角色</label>
                            <div class="layui-input-inline">
                                <% if (roleType === 0) { %>
                                <input type="text" name="roleType" value="超级管理员" readonly class="layui-input">
                                <%} else { %>
                                <input type="text" name="roleType" value="用户" readonly class="layui-input">
                                <% } %>
                            </div>
                            <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" value="<%=username%>" readonly
                                       class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                        </div>
                        <div class="layui-form-item" style="display: flex;">
                            <label class="layui-form-label">头像</label>
                            <div class="layui-input-inline" id="avatar-preview" style="width: unset;">
                                <div class="img-item">
                                    <img style="width: 100%;height: 100%;" src="<%=avatar%>" alt="头像" onclick="showimg(this)">
                                </div>
                            </div>
                            <div class="layui-input-inline layui-btn-container" style="width: unset;">
                                <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button id="submitBtn" class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/adminstatic/base/base.js"></script>
<script type="application/javascript">
    var url = $("input[name='url']").val();
    $('#avatar-preview img').attr('src', url);

    // //上传图片
    uploadImg('#LAY_avatarUpload', '/admin/upload/carouselImages/addFile', '#avatar-preview')


    $("#submitBtn").click(function () {
        var avatar = $('#avatar-preview img')[0].src;
        var id = $("input[name='id']").val();

        console.log(avatar);

        if (!vaildeParam(avatar)) {
            layer.msg("头像不能为空", {icon: 5});
            return;
        }

        var api = '/admin/updateInfo';
        var data = {
            "id": id,
            "avatar": avatar,
        }

        postJSON(api, data, function (res) {
            cleanSuccess(res)
        });

    });
</script>
</body>
</html>